home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / utilities / ppi_1.2.lha / PPI / PPI.e < prev    next >
Encoding:
Text File  |  1980-01-11  |  11.6 KB  |  477 lines

  1. /*
  2.  
  3. PPI - Programming Project Interface v1.2
  4.  
  5. Changed:
  6.     Workfile gadget is now a true Gadtools object, and
  7.     not an E TextF() statement.
  8.  
  9. Written by Vincent Platt - (c) 1994-1995 - All Rights Reserved
  10. Modifying & distributing this source is prohibited.
  11. Source may be modified for own personal use.
  12.  
  13. This program and its source are freeware and no charge may be
  14. made for this program, its source, or its documentation.
  15.  
  16. SrcGen used to create original code skeleton.
  17.  
  18. A modified version of Eformat was used to make things uniform.
  19. (My version makes indents a single space, rather than a tab char.)
  20.  
  21. I'm still using this bugger folks, and it hasn't crashed on me a single
  22. time!
  23.  
  24.  
  25. */
  26.  
  27. OPT OSVERSION=37
  28.  
  29. MODULE 'gadtools','libraries/gadtools','intuition/intuition',
  30. 'intuition/screens', 'intuition/gadgetclass', 'graphics/text',
  31. 'Asl', 'libraries/Asl', 'dos/dos'
  32.  
  33. ENUM NONE, NOCONTEXT, NOGADGET, NOWB, NOVISUAL, OPENGT, NOWINDOW, NOMENUS
  34. ENUM EDIT_BUTTON, COMPILE_BUTTON, ACTION1_BUTTON, ACTION2_BUTTON,
  35.  PICK_BUTTON, SAVESETTINGS_BUTTON, EDITOR_STRING, COMPILER_STRING,
  36.  ACTION1_STRING, ACTION2_STRING, KILL_CBOX, WORK_TEXT
  37. ENUM EDIT, COMPILE, ACTION1, ACTION2
  38.  
  39. DEF ppiwnd:PTR TO window, ppiglist, scr:PTR TO screen, visual=NIL,
  40. offx,offy,tattr,text_gad
  41.  
  42. /* strings for launch's and files */
  43.  
  44. DEF pickfile[256]:STRING, compile[256]:STRING, edit[256]:STRING,
  45. action1[256]:STRING, action2[256]:STRING
  46.  
  47. /* for the checkbox */
  48. DEF checked=TRUE
  49.  
  50. PROC setupscreen()
  51.  IF (gadtoolsbase:=OpenLibrary('gadtools.library',37))=NIL THEN RETURN OPENGT
  52. /* IF (scr:=LockPubScreen('Workbench'))=NIL THEN RETURN NOWB */
  53.  IF (scr:=LockPubScreen(NIL))=NIL THEN RETURN NOWB
  54.  IF (visual:=GetVisualInfoA(scr,NIL))=NIL THEN RETURN NOVISUAL
  55.  offy:=scr.wbortop+Int(scr.rastport+58)-10
  56.  tattr:=['topaz.font',8,0,0]:textattr
  57. ENDPROC
  58.  
  59. PROC closedownscreen()
  60.  IF visual THEN FreeVisualInfo(visual)
  61.  IF scr THEN UnlockPubScreen(NIL,scr)
  62.  IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
  63. ENDPROC
  64.  
  65. PROC openppiwindow()
  66.  DEF g:PTR TO gadget
  67.  IF (g:=CreateContext({ppiglist}))=NIL THEN RETURN NOCONTEXT
  68.  
  69.  IF (g:=CreateGadgetA(BUTTON_KIND,g,
  70.   [offx+410,offy+16,120,19,'_Edit',tattr,EDIT_BUTTON,16,visual,0]:newgadget,
  71.   [GT_UNDERSCORE,"_",
  72.   NIL]))=NIL THEN RETURN NOGADGET
  73.   IF (g:=CreateGadgetA(BUTTON_KIND,g,
  74.    [offx+410,offy+36,120,19,'_Compile',tattr,COMPILE_BUTTON,16,visual,0]:newgadget,
  75.    [GT_UNDERSCORE,"_",
  76.    NIL]))=NIL THEN RETURN NOGADGET
  77.    IF (g:=CreateGadgetA(BUTTON_KIND,g,
  78.     [offx+410,offy+56,120,19,'Action _1',tattr,ACTION1_BUTTON,16,visual,0]:newgadget,
  79.     [GT_UNDERSCORE,"_",
  80.     NIL]))=NIL THEN RETURN NOGADGET
  81.     IF (g:=CreateGadgetA(BUTTON_KIND,g,
  82.      [offx+410,offy+76,120,19,'Action _2',tattr,ACTION2_BUTTON,16,visual,0]:newgadget,
  83.      [GT_UNDERSCORE,"_",
  84.      NIL]))=NIL THEN RETURN NOGADGET
  85.      IF (g:=CreateGadgetA(BUTTON_KIND,g,
  86.       [offx+410,offy+96,120,19,'_Pick',tattr,PICK_BUTTON,16,visual,0]:newgadget,
  87.       [GT_UNDERSCORE,"_",
  88.       NIL]))=NIL THEN RETURN NOGADGET
  89.       IF (g:=CreateGadgetA(BUTTON_KIND,g,
  90.        [offx+410,offy+116,120,19,'_Save Settings',tattr,SAVESETTINGS_BUTTON,16,visual,0]:newgadget,
  91.        [GT_UNDERSCORE,"_",
  92.        NIL]))=NIL THEN RETURN NOGADGET
  93.  
  94.        IF (g:=CreateGadgetA(STRING_KIND,g,
  95.         [offx+96,offy+23,224,12,'Editor:',tattr,EDITOR_STRING,1,visual,0]:newgadget,
  96.         [GTST_MAXCHARS,256,GTST_STRING,edit,
  97.         NIL]))=NIL THEN RETURN NOGADGET
  98.         IF (g:=CreateGadgetA(STRING_KIND,g,
  99.          [offx+97,offy+42,224,12,'Compiler:',tattr,COMPILER_STRING,1,visual,0]:newgadget,
  100.          [GTST_MAXCHARS,256,GTST_STRING,compile,
  101.          NIL]))=NIL THEN RETURN NOGADGET
  102.          IF (g:=CreateGadgetA(STRING_KIND,g,
  103.           [offx+97,offy+61,224,12,'Action 1:',tattr,ACTION1_STRING,1,visual,0]:newgadget,
  104.           [GTST_MAXCHARS,256,GTST_STRING,action1,
  105.           NIL]))=NIL THEN RETURN NOGADGET
  106.           IF (g:=CreateGadgetA(STRING_KIND,g,
  107.            [offx+96,offy+80,224,12,'Action 2:',tattr,ACTION2_STRING,1,visual,0]:newgadget,
  108.            [GTST_MAXCHARS,256,GTST_STRING,action2,
  109.            NIL]))=NIL THEN RETURN NOGADGET
  110.  
  111.            IF (g:=CreateGadgetA(CHECKBOX_KIND,g,
  112.             [offx+170,offy+115,26,11,'Kill Extension For Compiling',tattr,KILL_CBOX,4,visual,0]:newgadget,
  113.             [GTCB_CHECKED,checked,
  114.             NIL]))=NIL THEN RETURN NOGADGET
  115.  
  116.             IF (g:=CreateGadgetA(TEXT_KIND,g,
  117.              [offx+96,offy+130,224,12,'Workfile: ',tattr,WORK_TEXT,1,visual,0]:newgadget,
  118.              [GTTX_BORDER,1,NIL]))=NIL THEN RETURN NOGADGET
  119.             text_gad:=g
  120.  
  121.             IF (ppiwnd:=OpenWindowTagList(NIL,
  122.              [WA_LEFT,0,
  123.              WA_TOP,17,
  124.              WA_WIDTH,offx+579,
  125.              WA_HEIGHT,offy+149,
  126.              WA_IDCMP,IDCMP_GADGETUP+IDCMP_CLOSEWINDOW+IDCMP_VANILLAKEY,
  127.              WA_FLAGS,WFLG_DEPTHGADGET+WFLG_SMART_REFRESH+WFLG_DRAGBAR+WFLG_CLOSEGADGET+WFLG_RMBTRAP,
  128.              WA_TITLE,'Programming Project Interface (PPI) 1.1 - © 1994 Vincent Platt',
  129.              WA_CUSTOMSCREEN,scr,
  130.              WA_MINWIDTH,67,
  131.              WA_MINHEIGHT,21,
  132.              WA_MAXWIDTH,$23A,
  133.              WA_MAXHEIGHT,145,
  134.              WA_AUTOADJUST,1,
  135.              WA_AUTOADJUST,1,
  136.              WA_GADGETS,ppiglist,
  137.              NIL]))=NIL THEN RETURN NOWINDOW
  138.              Gt_RefreshWindow(ppiwnd,NIL)
  139.  
  140. ENDPROC
  141.  
  142. PROC closeppiwindow()
  143.  IF ppiwnd THEN CloseWindow(ppiwnd)
  144.  IF ppiglist THEN FreeGadgets(ppiglist)
  145. ENDPROC
  146.  
  147. PROC reporterr(er)
  148.  DEF erlist:PTR TO LONG
  149.  IF er
  150.   erlist:=['get context','create gadget','lock wb','get visual infos',
  151.   'open "gadtools.library" v37+','open window','create menus']
  152.   EasyRequestArgs(0,[20,0,0,'Could not \s!','ok'],0,[erlist[er-1]])
  153.  ENDIF
  154. ENDPROC er
  155.  
  156. PROC request_file()
  157.  
  158.  DEF req:PTR TO filerequester
  159.  DEF a[2]:STRING
  160.  
  161.  IF aslbase:=OpenLibrary('asl.library',37)
  162.   IF req:=AllocFileRequest()
  163.    RequestFile(req)
  164.  
  165.    /* first see if the user bothered to pick a file, if not then get out */
  166.    IF StrCmp(req.file,'',ALL) THEN JUMP getout
  167.  
  168.    /* copy path name to our full file name string */
  169.    StrCopy(pickfile,req.drawer,ALL)
  170.  
  171.    /* tack a '/' on to the end of pickfile if req.drawer is not empty and
  172.    the last char of req.drawer is not ':' */
  173.    IF (StrCmp(req.drawer,'',ALL)=FALSE)
  174.     MidStr(a,req.drawer,StrLen(req.drawer)-1,ALL)
  175.     IF (StrCmp(a,':',ALL)=FALSE)
  176.      StrAdd(pickfile,'/',ALL)
  177.     ENDIF
  178.    ENDIF
  179.  
  180.    /* then tack the filename on to the end of pickfile */
  181.    StrAdd(pickfile,req.file,ALL)
  182.  
  183.    getout:
  184.    FreeFileRequest(req)
  185.   ELSE
  186.    WriteF('Could not open filerequester!\n')
  187.   ENDIF
  188.   CloseLibrary(aslbase)
  189.  ELSE
  190.   WriteF('Could not open asl.library!\n')
  191.  ENDIF
  192. ENDPROC
  193.  
  194.  
  195. PROC launch(whichone)
  196.  DEF orgstr[256]:STRING
  197.  DEF str[256]:STRING
  198.  DEF x, test[1]:STRING
  199.  DEF oldpickfile[256]:STRING
  200.  StrCopy(str,'',ALL)
  201.  
  202.  /* this is done so the compile section can mess with the pickfile
  203.  pickfile is restored when everything is done */
  204.  StrCopy(oldpickfile,pickfile,ALL)
  205.  
  206.  SELECT whichone
  207.  
  208.   CASE EDIT
  209.    StrCopy(orgstr,edit,ALL)
  210.  
  211.   CASE COMPILE
  212.    IF checked
  213.     FOR x:= StrLen(pickfile)-1 TO 0 STEP -1
  214.      MidStr(test,pickfile,x,1)
  215.      IF StrCmp(test,'.',ALL)
  216.       StrCopy(pickfile,pickfile,x)
  217.      ENDIF
  218.     ENDFOR
  219.    ENDIF
  220.    StrCopy(orgstr,compile,ALL)
  221.  
  222.   CASE ACTION1
  223.    StrCopy(orgstr,action1,ALL)
  224.  
  225.   CASE ACTION2
  226.    StrCopy(orgstr,action2,ALL)
  227.  
  228.  ENDSELECT
  229.  
  230.  FOR x:= 0 TO StrLen(orgstr)-1
  231.   MidStr(test,orgstr,x,1)
  232.   IF StrCmp(test,'%',ALL)
  233.    MidStr(test,orgstr,x+1,1)
  234.    IF StrCmp(test,'s',ALL)
  235.     StrAdd(str,pickfile,ALL)
  236.     INC x /* inc to skip the s as well as the % */
  237.     JUMP z /* don't add % and s chars now that they have been handled */
  238.    ELSE
  239.     StrAdd(str,'%',ALL)
  240.    ENDIF
  241.   ENDIF
  242.   StrAdd(str,test,ALL)
  243.   z:
  244.  ENDFOR
  245.  
  246.  Execute(str,0,0)
  247.  StrCopy(pickfile,oldpickfile,ALL)
  248.  
  249. ENDPROC
  250.  
  251.  
  252. PROC pick()
  253.  request_file()
  254.  change_work_text()
  255. ENDPROC
  256.  
  257. PROC change_work_text()
  258. /* here we change the contents of gadget WORK_TEXT to the new workfile */
  259.  Gt_SetGadgetAttrsA(text_gad,ppiwnd, NIL,
  260.                    [GTTX_TEXT, pickfile])
  261. ENDPROC
  262.  
  263. PROC savesettings()
  264.  DEF file
  265.  
  266.  IF file:= Open('s:PPI.prefs', NEWFILE)
  267.   Fputs(file,'PPI Prefs\n')
  268.  
  269.   Fputs(file,pickfile)
  270.   Fputs(file,'\n')
  271.  
  272.   Fputs(file,edit)
  273.   Fputs(file,'\n')
  274.  
  275.   Fputs(file,compile)
  276.   Fputs(file,'\n')
  277.  
  278.   Fputs(file,action1)
  279.   Fputs(file,'\n')
  280.  
  281.   Fputs(file,action2)
  282.   Fputs(file,'\n')
  283.  
  284.   IF checked
  285.    Fputs(file,'T\n')
  286.   ELSE
  287.    Fputs(file,'F\n')
  288.   ENDIF
  289.  
  290.   Close(file)
  291.  ENDIF
  292. ENDPROC
  293.  
  294. PROC loadsettings()
  295.  DEF file
  296.  DEF buf[260]:STRING
  297.  
  298.  IF file:= Open('s:PPI.prefs', OLDFILE)
  299.   Fgets(file,buf,260)
  300.  
  301.   StrCopy(buf,'',ALL)
  302.   Fgets(file,buf,260)
  303.   StrCopy(pickfile,buf,StrLen(buf)-1)
  304.  
  305.   StrCopy(buf,'',ALL)
  306.   Fgets(file,buf,260)
  307.   StrCopy(edit,buf,StrLen(buf)-1)
  308.  
  309.   StrCopy(buf,'',ALL)
  310.   Fgets(file,buf,260)
  311.   StrCopy(compile,buf,StrLen(buf)-1)
  312.  
  313.   StrCopy(buf,'',ALL)
  314.   Fgets(file,buf,260)
  315.   StrCopy(action1,buf,StrLen(buf)-1)
  316.  
  317.   StrCopy(buf,'',ALL)
  318.   Fgets(file,buf,260)
  319.   StrCopy(action2,buf,StrLen(buf)-1)
  320.  
  321.   StrCopy(buf,'',ALL)
  322.   Fgets(file,buf,260)
  323.   StrCopy(buf,buf,StrLen(buf)-1)
  324.  
  325.   IF StrCmp(buf,'F',ALL)
  326.    checked:=FALSE
  327.   ELSE
  328.    checked:=TRUE
  329.   ENDIF
  330.   Close(file)
  331.  
  332.  ELSE
  333.   Close(file)
  334.  ENDIF
  335. ENDPROC
  336.  
  337. PROC main()
  338.  DEF class, code, iaddress, dummy: PTR TO stringinfo, dummy2
  339.  DEF mes: PTR TO intuimessage
  340.  DEF clicked: PTR TO gadget, gadgetid
  341.  
  342.  loadsettings()
  343.  
  344.  IF reporterr(setupscreen())=0
  345.   reporterr(openppiwindow())
  346.  
  347.   stdrast:=ppiwnd.rport
  348.   change_work_text()
  349.  
  350.   LOOP
  351.    class:=FALSE
  352.    REPEAT
  353.     IF mes:=Gt_GetIMsg(ppiwnd.userport)
  354.      class:=mes.class
  355.      code:=mes.code
  356.      iaddress:=mes.iaddress
  357.      Gt_ReplyIMsg(mes)
  358.      IF class=IDCMP_REFRESHWINDOW
  359.       Gt_BeginRefresh(ppiwnd)
  360.       Gt_EndRefresh(ppiwnd,TRUE)
  361.       change_work_text()
  362.       class:=FALSE
  363.      ELSEIF ((class<>IDCMP_CLOSEWINDOW) AND (class<>IDCMP_GADGETUP) AND (class<>IDCMP_VANILLAKEY))
  364.       class:=FALSE
  365.      ENDIF
  366.     ELSE
  367.      WaitPort(ppiwnd.userport)
  368.     ENDIF
  369.    UNTIL class
  370.  
  371.    SELECT class
  372.  
  373.     CASE IDCMP_CLOSEWINDOW
  374.      BRA x
  375.  
  376.     CASE IDCMP_VANILLAKEY
  377.      /* here we must check to see if one of our hotkeys were pressed and
  378.      then react appropriately for each case */
  379.  
  380.      SELECT code
  381.  
  382.       /* "e" or "E" = Edit Button */
  383.       CASE "e"
  384.        launch(EDIT)
  385.       CASE "E"
  386.        launch(EDIT)
  387.  
  388.        /* "c" or "C" = Compile Button */
  389.       CASE "c"
  390.        launch(COMPILE)
  391.       CASE "C"
  392.        launch(COMPILE)
  393.  
  394.        /* "1" = Action1 Button */
  395.       CASE "1"
  396.        launch(ACTION1)
  397.  
  398.        /* "2" = Action2 Button */
  399.       CASE "2"
  400.        launch(ACTION2)
  401.  
  402.        /* "p" or "P" = Pick Button */
  403.       CASE "p"
  404.        pick()
  405.       CASE "P"
  406.        pick()
  407.  
  408.        /* "s" or "S" = SaveSettings Button */
  409.       CASE "s"
  410.        savesettings()
  411.       CASE "S"
  412.        savesettings()
  413.  
  414.      ENDSELECT
  415.  
  416.  
  417.     CASE IDCMP_GADGETUP
  418.      clicked:=iaddress
  419.      gadgetid:=clicked.gadgetid
  420.  
  421.      SELECT gadgetid
  422.       CASE EDIT_BUTTON
  423.        launch(EDIT)
  424.  
  425.       CASE COMPILE_BUTTON
  426.        launch(COMPILE)
  427.  
  428.       CASE ACTION1_BUTTON
  429.        launch(ACTION1)
  430.  
  431.       CASE ACTION2_BUTTON
  432.        launch(ACTION2)
  433.  
  434.       CASE PICK_BUTTON
  435.        pick()
  436.  
  437.       CASE SAVESETTINGS_BUTTON
  438.        savesettings()
  439.  
  440.       CASE EDITOR_STRING
  441.        dummy := clicked.specialinfo
  442.        dummy2 := dummy.buffer
  443.        StrCopy(edit, dummy2, ALL)
  444.  
  445.       CASE COMPILER_STRING
  446.        dummy := clicked.specialinfo
  447.        dummy2 := dummy.buffer
  448.        StrCopy(compile, dummy2, ALL)
  449.  
  450.       CASE ACTION1_STRING
  451.        dummy := clicked.specialinfo
  452.        dummy2 := dummy.buffer
  453.        StrCopy(action1, dummy2, ALL)
  454.  
  455.       CASE ACTION2_STRING
  456.        dummy := clicked.specialinfo
  457.        dummy2 := dummy.buffer
  458.        StrCopy(action2, dummy2, ALL)
  459.  
  460.       CASE KILL_CBOX
  461.        IF checked
  462.         checked:=FALSE
  463.        ELSE
  464.         checked:=TRUE
  465.        ENDIF
  466.  
  467.      ENDSELECT
  468.    ENDSELECT
  469.  
  470.   ENDLOOP
  471.  
  472.  ENDIF
  473.  x: closedownscreen()
  474.  closeppiwindow()
  475.  CleanUp(0)
  476. ENDPROC
  477.